<template>
  <div style="width: 600px">
    <div>
      <el-input prefix-icon="el-icon-search"
          placeholder="输入关键字进行搜索"
          v-model="filterText">
      </el-input>
    </div>
    <div>
      <el-tree
          class="filter-tree"
          :data="data"
          :props="defaultProps"
          :filter-node-method="filterNode"
          ref="tree">
      </el-tree>
    </div>
  </div>
</template>

<script>
export default {
  name: "DepMana",
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    }
  },
  mounted() {
    this.initData()
  },

  methods: {
    filterNode(value, data) {
      if (!value) return true;
      return data.name.indexOf(value) !== -1;
    },
    initData(){
      this.postRequest("/system/basic/department/getAllDepartment/").then(resp =>{
        console.log(JSON.stringify(resp))
        if (resp){
          this.data= resp
        }
      })
    }

  },

  data() {
    return {
      filterText: '',
      data: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      }
    };
  }
}
</script>

<style scoped>


</style>